/*
 * @Author: wurangkun
 * @Date: 2024-07-12 21:53:25
 * @LastEditTime: 2024-07-24 11:17:14
 * @LastEditors: wurangkun
 * @FilePath: \my-app\app\pages\userInfo\index.tsx
 * @Description: 
 */
import { ScreenBar } from '@/components/ScreenBar'
import { router, Stack, useFocusEffect, useNavigation } from 'expo-router'
import React, { useEffect } from 'react'
import { View, Text, ScrollView } from 'react-native'
import { SafeAreaView } from 'react-native-safe-area-context'

import { PickerView, Button } from '@ant-design/react-native'
import { StackActions, useRoute } from '@react-navigation/native'
import { relaunch, toHome } from '@/hooks/routerHooks'
import Page from '@/components/page'

const basicColumns = [
  [
    { label: '周一', value: 'Mon' },
    { label: '周二', value: 'Tues' },
    { label: '周三', value: 'Wed' },
    { label: '周四', value: 'Thur' },
    { label: '周五', value: 'Fri' },
  ],
  [
    { label: '上午', value: 'am' },
    { label: '下午', value: 'pm' },
  ],
]
export default function Userinfo() {
  const [visible, setVisible] = React.useState(undefined);
  const onChange = (e: any) => setVisible(e)
  const navigation = useNavigation();

  useEffect(() => {
    console.log('组件已挂载');

    return () => { console.log('组件即将卸载') }
  })
  // const toHome = () => {
  //   navigation.dispatch(StackActions.popToTop());
  //   router.replace('/')
  // }

  // useEffect(() => {
  //   // 组件已挂载，可以在这里执行需要的操作  
  //   console.log('组件已挂载');

  //   // 清理函数（可选）  
  //   return () => {
  //     // 组件卸载前执行的清理工作  
  //     console.log('组件即将卸载');
  //   };
  // }, [])
  // //  
  // useFocusEffect(
  //   React.useCallback(() => {
  //     // 这里会在路由聚焦时运行  
  //     console.log('路由聚焦了');

  //     // 清理函数（可选）  
  //     return () => {
  //       // 这里会在路由失去焦点时运行  
  //       console.log('路由失去焦点了');
  //     };
  //   }, []) // 依赖项数组  
  // );

  return (
    < >
      <Page title='个人信息'>
        <View style={{ flex: 1, backgroundColor: "#f6f7f9" }}>
          <ScrollView scrollEnabled={true} style={{ width: '100%' }}>
            <SafeAreaView edges={['bottom']} style={{ flex: 1, width: '100%', }}>
              <Button onPress={() => relaunch('/pages/haha')}>213</Button>
              <Text style={{ margin: 16 }}>基础用法</Text>
              <PickerView data={basicColumns} cascade={false} />
              <Text style={{ margin: 16 }}>自定义高度</Text>
              <PickerView
                data={basicColumns}
                cascade={false}
                style={{ height: 450 }}
                itemHeight={55}
                itemStyle={{
                  padding: 0,
                }}
              />

              <Text style={{ margin: 16 }}>受控模式</Text>
              <PickerView
                onChange={onChange}
                value={visible}
                data={basicColumns}
                cascade={false}
              />

              <Text style={{ margin: 16 }} />
            </SafeAreaView>
          </ScrollView>
        </View >
      </Page>

    </>
  )
}
